<template>
  <el-dialog
    :visible.sync="$attrs.visableIf"
    @close="handleCloseDialog"
    width="700px"
    append-to-body
    class="borderb_dia"
  >
    <div slot="title" style="font-size: 14px; font-weight: 500">选择标签</div>
    <div class="tag-card">
      <div class="card-head">
        <el-input
          placeholder="搜索标签/标签组"
          v-model="queryParams.keyword"
          size="small"
          class="x-input-select"
          @keyup.enter.native="handleQuery"
          style="width: 200px"
        >
          <el-button
            slot="append"
            size="small"
            icon="el-icon-search"
          ></el-button>
        </el-input>
        <!-- <el-input class="search-input" size="small" placeholder="搜索标签/标签组" suffix-icon="el-icon-search" style="width: 200px;"/> -->
        <div class="search-tags">
          <el-switch size="mini" />
          仅显示已选中标签
        </div>
      </div>
      <div class="card-body">
        <div v-for="(item, index) in dataList" :key="index">
          <div class="label-title">{{ item.label }}</div>
          <div class="label-list">
            <span
              v-for="(child, cindex) in item.children"
              :key="cindex"
              class="label-tag"
              :class="{ active: checkItem && checkItem.id == child.id }"
              @click="handleClick(child)"
              >{{ child.label }}</span
            >
          </div>
        </div>
        <!-- <div>
          <div class="label-title">可爱爱</div>
          <div class="label-list">
            <span class="label-tag">可爱爱</span>
            <span class="label-tag">恶心心</span>
            <span class="label-tag">可呜呜</span>
          </div>
        </div>
        <div>
          <div class="label-title">个人标签</div>
          <div class="label-list"></div>
        </div> -->
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleCloseDialog">取 消</el-button>
      <el-button size="small" type="primary" @click="handleSubmit"
        >确 定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      queryParams: {
        keyword: "",
      },
      checkItem: null,
      dataList: [
        {
          label: "分组一",
          id: 1,
          children: [
            { id: 2, label: "标签一", checked: false },
            { id: 3, label: "标签二", checked: false },
          ],
        },
        {
          label: "分组二",
          id: 5,
          children: [
            { id: 6, label: "标签一", checked: false },
            { id: 7, label: "标签二", checked: false },
          ],
        },
        {
          label: "个人标签",
          id: 8,
          children: [],
        },
      ],
    };
  },
  props: {
    label: {
      type: Object,
      default: null,
    },
  },
  created(){
    if(this.label){
        this.checkItem = this.label
    }
  },
  methods: {
    handleCloseDialog() {
      this.$emit("update:visableIf", false);
    },

    handleClick(item) {
      this.checkItem = item;
    },

    handleSubmit() {
      this.$emit("submit", this.checkItem);
      this.handleCloseDialog()
    },
  },
};
</script>

<style scoped lang="scss">
.tag-card {
  border: 1px solid #e9e9e9;
  .card-head {
    display: flex;
    background-color: #f9f9f9;
    height: 44px;
    align-items: center;
    outline: 1px solid #e9e9e9;
    padding: 0 16px;
    justify-content: space-between;
    font-size: 14px;
    line-height: 22px;
  }
  .card-body {
    padding: 16px;
    max-height: 420px;
    overflow-y: auto;
    .label-title {
      display: inline-block;
      color: rgba(0, 0, 0, 0.45);
      font-size: 12px;
      margin-bottom: 8px;
    }
    .label-list {
      margin-bottom: 16px;
      .label-tag {
        display: inline-block;
        background: rgba(0, 0, 0, 0.04);
        border-radius: 2px;
        border: 1px solid rgba(0, 0, 0, 0.15);
        font-size: 12px;
        line-height: 20px;
        padding: 3px 8px;
        cursor: pointer;
        margin-right: 8px;
        margin-bottom: 8px;
        &:hover {
          color: #2f54eb;
        }
        &.active {
          color: #2f54eb;
          border-color: #2f54eb;
          background-color: #fff;
        }
      }
    }
  }
}
</style>
